﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace ch04
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //源图片的路径及名称
            string pic = @"D:\CS架构编程\img\2.jpg";
            //要复制到哪里的位置(目录)
            string path = @"C:\Users\Administrator\Desktop\2.jpg";
            //创建读取器(输入流)
            FileStream sr = new FileStream(pic,FileMode.Open);
            //创建写入器(输出流)
            FileStream sw = new FileStream(path,FileMode.Create);
            //定义字节数组用于保存每次读取的内容
            byte[] b = new byte[1024];
            //定义变量保存每次读取的字节总数
            int len;
            //循环的从源文件读取内容，并写入到目标位置
            while ((len = sr.Read(b, 0, b.Length))!= 0)
            {
                //读多少字节就写入多少字节
                sw.Write(b, 0, len);
            }
            //释放资源
            sw.Close();
            sr.Close();

            MessageBox.Show("复制成功！");
        }
    }
}
